package com.utils.redis;

import java.util.Map;
import java.util.Map.Entry;

import com.google.common.collect.Maps;

import redis.clients.jedis.Jedis;

public class LocalRedis {
	    public static void main(String[] args) {
//	    	4.5394110
//	    	String masterkey = "advConsume||2019-08-26||pixels||7";
	    	String masterkey1 = "selfAdv||2020-03-17||clicks||feihuanadx||toutiao";//453.9411
	    	String masterkey2 = "selfAdv||2020-03-16||clicks||feihuanadx||toutiao";//453.9411
	    	String masterkey3 = "selfAdv||2020-03-15||clicks||feihuanadx||toutiao";//453.9411
	    	String masterkey4 = "selfAdv||2020-03-14||clicks||feihuanadx||toutiao";//453.9411
	    	String masterkey5 = "selfAdv||2020-03-13||clicks||feihuanadx||toutiao";//453.9411
	    	String masterkey6 = "selfAdv||2020-03-12||clicks||feihuanadx||toutiao";//453.9411
	    	String masterkey7 = "selfAdv||2020-03-11||clicks||feihuanadx||toutiao";//453.9411
	    	String masterkey8 = "selfAdv||2020-03-10||clicks||feihuanadx||toutiao";//453.9411
	    	Map<String,String> map = Maps.newHashMap();
	    	map.put("2020-03-17", masterkey1);
	    	map.put("2020-03-16", masterkey2);
	    	map.put("2020-03-15", masterkey3);
	    	map.put("2020-03-14", masterkey4);
	    	map.put("2020-03-13", masterkey5);
	    	map.put("2020-03-12", masterkey6);
	    	map.put("2020-03-11", masterkey7);
	    	map.put("2020-03-10", masterkey8);
	        //连接本地的 Redis 服务
//	        Jedis jedis = new Jedis("localhost");
	        Jedis jedis = new Jedis("127.0.0.1", 10233,10000,10000);
	        jedis.select(11);
	        System.out.println("连接成功");
	        
	        for (Entry<String,String> entry1 : map.entrySet()) {
	        	
	        	Map<String, String> result = jedis.hgetAll(entry1.getValue());
	        	int sum=0;
	        	
	        	Map<String, Integer> ouradid = Maps.newHashMap();
	        	
	        	
	        	for (Entry<String,String> entry : result.entrySet()) {
	        		int num = Integer.valueOf(entry.getValue().replace("\"", ""));
	        		String [] key = entry.getKey().split("\\|\\|");
	        		if(ouradid.containsKey(key[0]+"||"+key[1])) {
	        			ouradid.put(key[0]+"||"+key[1], ouradid.get(key[0]+"||"+key[1])+num);
	        		}else {
	        			ouradid.put(key[0]+"||"+key[1], num);
	        		}
	        		sum+=num;
//	        		System.out.println("adid="+key[0]+","+"\t"+"ouradid="+key[1]+"\t"+"数量="+entry.getValue().replace("\"", ""));
	        	}
	        	
	        	for (Entry<String,Integer> entry : ouradid.entrySet()) {
	        		System.out.println(entry.getKey()+","+"\t"+"数量="+entry.getValue());
	
				}
	        	
	        	
	        	System.out.println(entry1.getKey()+"\t"+"总数="+sum);
	        	System.out.println("-----------------------------------------------");

			}
	        
			//查看服务是否运行
	        System.out.println("服务正在运行: "+jedis.ping());
//	        System.out.println(36347+87124);
	    }
}
